var count = 0;

function CheckVaildEmail(Email)
{
	var filter =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(Email))
		return true;
	else
		return false;
}

function CheckVaildNumber(Number)
{
	if (Number.length > 7){
		var filter = "+- 1234567890()"
		for (i = 0; i < Number.length; i++){   
		    var c = Number.charAt(i);
		    if(filter.indexOf(c) < 0)
			return false;
		}
		return true;
	}else{
		return false;
	}
}

function ClearDisplay(ID)
{
	document.getElementById(ID).innerHTML = "";
}

function DisplayMsg(ID,Msg)
{
	document.getElementById(ID).innerHTML = Msg;
	setTimeout(function(){ClearDisplay(ID)},3000);
}

function CheckFields()
{
	var Name	= document.getElementById("Name").value;
	var Email	= document.getElementById("Mail").value;
	var Number	= document.getElementById("MobNo").value;
	var Operator= document.getElementById("Operator").value;
	var Circle	= document.getElementById("Circle").value;

	if(Name.length == 0){
		DisplayMsg("msg","<br><div class=\"msg\"><div class=\"correct\"> Enter a valid name...</div></div>");
		return false;
	}else if(Email.length == 0){
		DisplayMsg("msg","<br><div class=\"msg\"><div class=\"correct\"> Enter a valid email id...</div></div>");
		return false;
	}else if(CheckVaildEmail(Email) == false){
		DisplayMsg("msg","<br><div class=\"msg\"><div class=\"correct\"> Enter a valid email id...</div></div>");
		return false;
	}else if(Number.length == 0){
		DisplayMsg("msg","<br><div class=\"msg\"><div class=\"correct\"> Enter a valid mobile number...</div></div>");
		return false;
	}else if(CheckVaildNumber(Number) == false){
		DisplayMsg("msg","<br><div class=\"msg\"><div class=\"correct\"> Enter a valid mobile number...</div></div>");
		return false;
	}else if(Operator == ""){
		DisplayMsg("msg","<br><div class=\"msg\"><div class=\"correct\"> Choose your network operator...</div></div>");
		return false;
	}else if(Circle == ""){
		DisplayMsg("msg","<br><div class=\"msg\"><div class=\"correct\"> Choose your network circle...</div></div>");
		return false;
	}
	
	
	return true;
}

function CallSuccessPage(Name, Email, Number)
{
	document.getElementById("Name").value = Name;
	document.getElementById("Mail").value = Email;
	document.getElementById("MobNo").value = Number;
	var Form = document.getElementById("SuccessForm");
	Form.submit();
}

function InitiateTimer(Name, Email, Number)
{
	setTimeout(function(){CallSuccessPage(Name, Email, Number)},6000);
}
